include:
  - webserver.nginx
  - php.composer
  - dos2unix
  - supervisor

exclude:
  - id: 'Apply sysctl kernel.shmmax for Apcu issue' # Skip Kernel's settings changes
  - id: 'php-fpm' # Skip autostart php-fpm service, delegate to Supervisor
  - id: 'Enable nginx service' # Skip autostart nginx service, delegate to Supervisor
  - httpd.optimization # Skip Kernel's settings changes & open port

{% for storage_path in salt['pillar.get']('app:papi:api_storage_path',[]) %}
Set permission for PAPI storage directory {{ storage_path }}:
  file.directory:
    - name: {{ storage_path }}
    - user: nginx
    - group: nginx
    - mode: 775
    - recurse:
        - user
        - group
        - mode
{% endfor %}

Setup purge log script:
  file.managed:
    - name: /root/purge-api-logs.sh
    - source: salt://app/papi/purge-api-logs.sh
    - template: jinja

Create crontab file if not exist:
  file.managed:
    - name: /root/crontab.txt

Insert purge script into crontab:
  file.blockreplace:
    - name: /root/crontab.txt
    - marker_start: "# START saltstack generated crontab entries (for papi)"
    - marker_end:   "# END   saltstack generated crontab entries (for papi)"
    - content: 0 0 * * * sh /root/purge-api-logs.sh
    - backup: '.bak'
    - append_if_not_found: True

  cmd.run:
    - name: crontab /root/crontab.txt
